package com.lc.tgxm.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.lc.tgxm.activity.PhotoActivity;
import com.lc.tgxm.util.ImageUtils;
import com.lc.tgxm.util.PhotoViewInterface;
import com.zcx.helper.photo.PhotoView;

import java.util.ArrayList;


/**
 * PhotoPagerAdapter
 * Created by Hasee on 2018/5/12.
 */
public class PhotoPagerAdapter extends PagerAdapter {
    private ArrayList<PhotoViewInterface> mlist;
    private PhotoActivity mContext;

    public PhotoPagerAdapter(ArrayList<PhotoViewInterface> picarr, PhotoActivity context) {
        this.mlist = picarr;
        this.mContext = context;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        final PhotoView imageView = new PhotoView(mContext);

//        GlideLoader.getInstance().get(mContext, mlist.get(position).getPicUrl(), imageView);
        ImageUtils.glideLoader(mlist.get(position).getPicUrl(), imageView);

        container.addView(imageView);

        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
